package com.anpy.common.service.exception;

import com.anpy.common.service.model.vo.ResponseMessage;
import com.anpy.common.service.model.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(value = BusinessException.class)
    public ResponseMessage<Result> bizExceptionHandler(BusinessException e) {
        log.error(e.getMessage(), e);
        return Result.error(e.getMessage());
    }

    /**
     * 处理其他异常
     */
    @ExceptionHandler(value = Exception.class)
    public ResponseMessage<Result> exceptionHandler(Exception e) {
        log.error(e.getMessage(), e);
        return Result.error(e.getMessage());

    }
}
